﻿/* 功能:  汇率管理
 * 创建人：Kencery  创建时间：2018-2-1
 */
var ml = window.ml || {};
ml.admin = ml.admin || {};

ml.admin.currency = (function () {

    var defaults = {
        listUrl: "/Currency/List",
    };
    var opt = {};

    var columns = [{
        field: 'state',
        radio: true
    }, {
        title: '行号',
        field: 'number',
        align: 'center',
        hide: true,
        formatter: plscommon.tableNumber
    }, {
        title: '币种',
        field: 'Name',
    }, {
        title: '买入价',
        field: 'BuyCurrency',
        align: 'center',
    }, {
        title: '卖出价',
        field: 'SellCurrency',
        align: 'center',
    }, {
        title: '创建时间',
        field: 'CreateTime',
        align: 'center',
    }];

    var initTable = function () {
        plscommon.bootstraptable({
            id: "#currencyinfo",
            url: defaults.listUrl,
            queryParams: queryParams,
            uniqueId: "Id",
            columns: columns
        });
    }

    var queryParams = function (params) {
        return {
            offset: params.offset,             //后台计算显示数据信息
            pagesize: params.limit,            //每页显示多少行
            name_search: $("#name_search").val()
        };
    };

    var clickEvent = function () {
        $("#btnQueryList").on("click", function () { btnQueryList(); });                      //按条件查询结果
        $("#btnReset").on("click", function () { btnReset(); });                              //清空文本框信息
    };

    var btnQueryList = function () {
        plscommon.refreshTable("currencyinfo");
    }

    var btnReset = function () {
        plscommon.resetFrom("formSearch");
    }

    var btnReceivables = function () {
        var data = plscommon.dialogWaring('merchantinfo', 'QueryReceivables', 'QueryReceivablesOperation');
        if (!data.Id) {
            return false;
        }
        $("#HeadTitle_Receivables").text("(" + data.Name + ")商户收款方式");

        //发送请求调用查询后台返回数据
        $("#btnReceivables").prop("disabled", true);
        plscommon.ajax({
            disableId: "btnReceivables",
            url: defaults.getReceivablesByMerchantIdUrl,
            type: "GET",
            data: { id: data.Id },
            success: function () {
                var data = this.data;
                if (data.length > 0) {
                    $("#QueryReceivablesTable").show();
                    $("#QueryReceivablesTableNo").hide();

                    //不为空写入查询出来的内容
                    $("#QueryReceivablesTable table tbody").html("");
                    var tbody_tr = "";
                    $.each(data, function (i, item) {
                        var defaultmarktext = item.DefaultMark == 0 ? "未默认" : "默认";
                        tbody_tr += "<tr><td>" + item.Method + "</td><td>" + item.OpeningBank + "</td><td>" + item.OpeningName + "</td>"
                            + "<td>" + item.OpeningAccount + "</td><td>" + item.ThirdAccount + "</td>"
                            + "<td>" + defaultmarktext + "</td><td>" + item.CreateTime + "</td></tr>";
                    });
                    $("#QueryReceivablesTable table tbody").append(tbody_tr);
                } else {
                    $("#QueryReceivablesTable").hide();
                    $("#QueryReceivablesTableNo").show();
                }
            }
        });
    }

    return {
        init: function (options) {
            $.extend(defaults, options || {});
            initTable();            //初始化Table表格
            clickEvent();           //触发事件
        }
    };
}());